import { UserModel } from "@/database";

/**
 * 用户注册
 * @url /api/v1/register.post
 * @method POST
 * @param {string} username 用户名
 * @param {string} password 密码
 * @param {string} repeatPassword 重复密码
 * @param {string} email 邮箱
 * @param {string} code 验证码
 */
export default defineEventHandler(async (event) => {
    const body = await readBody(event)
    const isExist = UserModel.some((item) => item.username === body.username)
    if (isExist) return failApi('用户名已存在')
    if (body.password !== body.repeatPassword) {
        return failApi('两次密码不一致')
    }
    return successApi('注册成功')
})